// created on 2/26/2006 at 8:41 PM
using System;
using System.Net;
using System.Collections;
using CookComputing.XmlRpc;

namespace Whitemice.MOGI.RPC2 {

	public static class RPC2
	{
		public static bool IsEmptyResult(XmlRpcTypeMismatchException xmlException)
		{
			if (xmlException.Message == "response contains boolean value where struct expected [response]")
				return true;
			return false;
		}
		
		public static string ShortId(string longId)
		{
			return longId.Substring(longId.LastIndexOf('/') + 1);
		}
		
		public static ETaskStatus TaskStatusFromRPCString(string rpcString)
		{
		  	switch (rpcString) 
		  	{
				case "00_created": return ETaskStatus.Created;
				case "02_rejected": return ETaskStatus.Rejected;
				case "05_accepted": return ETaskStatus.Accepted;
				case "10_archived": return ETaskStatus.Archived;
				case "10_commented": return ETaskStatus.Commented;
				case "15_divided": return ETaskStatus.Divided;
				case "20_processing": return ETaskStatus.Processing;
				case "25_done": return ETaskStatus.Done;
				case "27_reactivated": return ETaskStatus.Reactivated;
				case "30_archived": return ETaskStatus.Archived;
				default: return ETaskStatus.Created;
		  	}		
		}
		
		public static string RPCStringFromTaskStatus(ETaskStatus status)
		{
		  	switch (status) 
		  	{
		   		case ETaskStatus.Created: return "00_created";
		   		case ETaskStatus.Rejected: return "02_rejected"; 
		   		case ETaskStatus.Accepted: return "05_accepted"; 
		   		case ETaskStatus.Archived: return "10_archived"; 
		   		case ETaskStatus.Commented: return "10_commented"; 
		   		case ETaskStatus.Divided: return "15_divided"; 
		   		case ETaskStatus.Processing: return "20_processing"; 
		   		case ETaskStatus.Done: return "25_done";	
		   		case ETaskStatus.Reactivated: return "27_reactivated";
		  	}
		  	return "10_commented";
		}
		
		public static string RPCStringFromTaskStatusKey(string key)
		{
			switch(key)
			{
				case "created": return RPCStringFromTaskStatus(ETaskStatus.Created);
				case "processing": return RPCStringFromTaskStatus(ETaskStatus.Processing);
				case "accepted": return RPCStringFromTaskStatus(ETaskStatus.Accepted);
				case "rejected": return RPCStringFromTaskStatus(ETaskStatus.Rejected);
				case "divided": return RPCStringFromTaskStatus(ETaskStatus.Divided);
				case "done": return RPCStringFromTaskStatus(ETaskStatus.Done);
				case "reactivated": return RPCStringFromTaskStatus(ETaskStatus.Reactivated);
				default: return RPCStringFromTaskStatus(ETaskStatus.Archived);
			}
		}
	}
}